﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

namespace PM.Code.Web
{
    /// <summary>
    /// 基本的对话框提示
    /// </summary>
    public class alertmessage
    {
        public alertmessage()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        /// <summary>
        /// 输出自定义脚本信息
        /// </summary>
        /// <param name="script">脚本</param>
        public static void ResponseScript(string script)
        {
            HttpContext.Current.Response.Write("<script language='javascript' defer>" + script + "</script>");
        }
        /// <summary>
        /// 显示提示信息
        /// </summary>
        /// <param name="AlertMessage"></param>
        public static void ShowDialog(string AlertMessage)
        {
            HttpContext.Current.Response.Write("<script>window.showModalDialog('" + AlertMessage + "',  window, 'dialogHeight:600px;dialogWidth:540px;center:yes;status:no;help:no;scroll:yes')</script>");
        }

        //显示JavaScript的Alert信息
        public static void ShowMsg(Page thisPage, string AlertMessage)
        {
            Literal txtMsg = new Literal();
            txtMsg.Text = "<script>alert('" + AlertMessage + "')</script>" + "<BR/>";
            thisPage.Controls.Add(txtMsg);
        }
        /// <summary>
        /// page_Load中使用Alert
        /// </summary>
        /// <param name="AlertMessage">警告信息</param>
        public static void ShowMsg(string AlertMessage)
        {
            HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + AlertMessage + "');</script>");
        }
        ///<summary>
        ///显示消息提示对话框后跳转到新页面
        ///</summary>
        ///<param name="AlertMessage">警告信息</param>
        ///<param name="NewPage">跳转到的新页面</param>
        public static void ShowMsg(string AlertMessage,string NewPage)
        {
            HttpContext.Current.Response.Write(" <script>alert('"+AlertMessage+"');location.href='"+NewPage+"'; </script>");
        }
        /// <summary>
        /// 显示消息提示对话框(使用UpdatePanel)
        /// </summary>
        /// <param name="updatepanel">UpdatePanel控件</param>
        /// <param name="AlertMessage">警告内容</param>
        public static void ShowMsg(UpdatePanel updatepanel, string AlertMessage)
        {
            ScriptManager.RegisterClientScriptBlock(updatepanel,updatepanel.Page.GetType(), "clientScript", "alert('"+AlertMessage+"');", true);
        }
        /// <summary>
        /// 跳转到其他页面(使用updatepanel的情况下)
        /// </summary>
        /// <param name="updatepanel">updatepanel</param>
        /// <param name="newurl">新url</param>
        public static void TurnToPage(UpdatePanel updatepanel,string newurl)
        {
            ScriptManager.RegisterClientScriptBlock(updatepanel, updatepanel.Page.GetType(), "click", "location.replace('" + newurl + "')", true);
        }
        /// <summary>
        /// 显示消息提示对话框(使用jquery easy UI)
        /// </summary>    
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="title">对话框标题</param>
        /// <param name="msg">对话框内容</param>
        /// <param name="kind">对话框形式(警告,提示,错误,疑问)</param>
        public static void ShowEUIMsg(System.Web.UI.Page page,string title, string msg, string kind)
        {
            string thekind;
            if (kind == "警告") thekind = "warning";
            else if (kind == "提示") thekind = "info";
            else if (kind == "错误") thekind = "error";
            else if (kind == "疑问") thekind = "question";
            else thekind = "";
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "$.messager.alert('" + title + "','" + msg + "','" + thekind + "');", true);
        }

        /// <summary>
        /// 显示消息提示对话框(使用jquery easy UI)
        /// </summary>    
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="title">对话框标题</param>
        /// <param name="msg">对话框内容</param>
        /// <param name="kind">对话框形式(警告,提示,错误,疑问)</param>
        /// <param name="url">跳转的目标页面</param>
        public static void ShowEUIMsg(System.Web.UI.Page page, string title, string msg, string kind,string url)
        {
            string thekind;
            if (kind == "警告") thekind = "warning";
            else if (kind == "提示") thekind = "info";
            else if (kind == "错误") thekind = "error";
            else if (kind == "疑问") thekind = "question";
            else thekind = "";
            string script = "$.messager.alert('" + title + "','" + msg + "','" + thekind + "');" + "location.href = '" + url + "';";
            page.ClientScript.RegisterStartupScript(page.GetType(), "", script, true);
        }

        /// <summary>
        /// 显示js的Confirm
        /// </summary>
        /// <param name="thisPage"></param>
        /// <param name="AlertMessage"></param>
        public static void ShowConfirm(Page thisPage, string AlertMessage)
        {
            Literal txtMsg = new Literal();
            txtMsg.Text = "<script>confirm('" + AlertMessage + "')</script>" + "<BR/>";
            thisPage.Controls.Add(txtMsg);
        }
        /// <summary>
        /// page_Load中使用Confirm
        /// </summary>
        /// <param name="AlertMessage">确认信息</param>
        public static void ShowConfirm(string AlertMessage)
        {
            HttpContext.Current.Response.Write("<script>confirm('" + AlertMessage + "')</script>");
        }
        /// <summary>
        /// js跳转页面
        /// </summary>
        /// <param name="thisPage">原页面</param>
        /// <param name="toPage">目标页面</param>
        public static void TurnToPage(Page thisPage, string toPage)
        {
            Literal txtMsg = new Literal();
            txtMsg.Text = "<script>top.location.replace('" + toPage + "')</script>" + "<BR/>";
            thisPage.Controls.Add(txtMsg);
        }
        /// <summary>
        /// page_Load中使用js跳转页面
        /// </summary>
        /// <param name="toPage">目标页面</param>
        public static void TurnToPage(string toPage)
        {
            HttpContext.Current.Response.Write("<script>top.location.replace('" + toPage + "')</script>");
        }
        /// <summary>
        /// 控件点击，消息确认提示框
        /// </summary>
        /// <param name="Control">WebControl</param>
        /// <param name="msg">提示信息</param>
        public static void ControlBindConfirm(WebControl Control, string msg)
        {
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }

        public static void ShowEUIMsg(Page page)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
